// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html

var Room = cc.Class({
    extends: cc.Component,
    statics: {
        Status: {
            WAIT: 1,
            PLAY: 2,
            END: 3
        },
        DecisionType: {
            //接炮胡
            TAKE_CANNON_WIN: 1,
            //自摸胡
            SELF_DRAWN_WIN: 2,
            //碰
            PUNG: 5,
            //吃
            EAT: 6,
            //明杠
            BRIGHT_BAR: 8,
            //暗杠
            DARK_BAR: 7,
            //眀补
            BRIGHT_BU: 4,
            //暗补
            DARK_BU: 3,
            //听牌
            LISTEN_BAR: 9,
        },
        PlayerTotal: 4,
    },

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    init() {
        this.m_status = Room.Status.WAIT;
        this.m_ready = [1, 1, 1, 1];
        this.m_players = {};
        this.m_nTotalPlayerCnt = Room.PlayerTotal;
    },

    //设置房间号
    setId(_id) {
        this.m_id = _id;
    },

    //获取房间号
    getId() {
        return this.m_id;
    },

    //座位偏移值
    setSeatOffset(_seatOffset) {
        this.m_seatOffset = _seatOffset;
    },

    getSeatRocation() {
        return (- this.m_seatOffset + 1) * 90;
    },

    //获得进入房间玩家数量
    getPlayerTotal() {
        var total = 0;
        for (var o in this.m_players) {
            total = total + 1;
        }
        return total;
    },

    isFull() {
        if (this.getPlayerTotal() == this.m_nTotalPlayerCnt) {
            return true;
        }
        return false;
    },

    getSeatOffset() {
        return this.m_seatOffset;
    },

    //向桌子添加一位玩家
    addPlayer(_player) {
        if (!_player.m_seatIdx) {
            return false;
        }
        this.m_players[_player.m_seatIdx] = _player;
    },

    //通过服务器给定位置m_pos + 1 = _seatIdx获取玩家
    getPlayer(_seatIdx) {
        return this.m_players[_seatIdx];
    },

    //移除一个玩家
    removePlayer(_seatIdx) {
        this.m_players[_seatIdx] = null;
    },

    //获取玩家列表
    getPlayers() {
        return this.m_players;
    },

    //设置房间内主视角位置
    setMainSeatIdx(_mainSeatIdx) {
        this.m_mainSeatIdx = _mainSeatIdx;
    },

    getMainSeatIdx() {
        return this.m_mainSeatIdx;
    },

    //获取主视角玩家对象
    getMainPlayer() {
        return this.m_players[this.m_mainSeatIdx];
    },

    //上一家出牌
    setPreShowSeatIdx(_preShowSeatIdx) {
        this.m_preShowSeatIdx = _preShowSeatIdx;
    },

    getPreShowSeatIdx() {
        return this.m_preShowSeatIdx;
    },

    //房间状态
    getRoomStatus() {
        return this.m_status;
    },

    setRoomStatus(_status) {
        this.m_status = _status;
    },

    setRound(_round) {
        this.m_round = _round;
    },

    getRuond() {
        return this.m_round;
    },

    endRound() {
        this.setRoomStatus(Room.Status.END);
        this.m_ready = [0, 0, 0, 0];
    },

    getReady(_seatIdx) {
        return this.m_ready[_seatIdx] ? this.m_ready[_seatIdx] : 0;
    },

    setReady(_seatIdx, _type) {
        this.m_ready[_seatIdx] = _type;
    },

    start() {

    },

    // update (dt) {},
});
